﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="linkSkill.aspx.cs" Inherits="Staff_skill_linkSkill" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">



        .style1
        {
            font-family: 微軟正黑體;
            font-size: xx-large;
            text-align: center;
        }
        .style2
        {
            text-align: center;
        }
        .style3
        {
            width: 84%;
        }
        .style4
        {
            height: 20px;
        }
        .style5
        {
            height: 20px;
            color: #FFFF00;
            background-color: #000000;
        }
        .style6
        {
            color: #66FF33;
            background-color: #000000;
        }
        .style7
        {
            height: 20px;
            color: #FF0000;
            background-color: #000000;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div class="style2">
    
        <span class="style1">新增學生技能資料</span><br />
        <br />
        <table align="center" class="style3">
            <tr>
                <td colspan="2">
                    輸入學生證號： 
                    <asp:TextBox ID="TextBox1" runat="server" ValidationGroup="phone"></asp:TextBox>
&nbsp;<asp:Button ID="Button1" runat="server" Text="查詢" onclick="Button1_Click" 
                        ValidationGroup="phone" />
                </td>
            </tr>
            <tr>
                <td>
                    &nbsp;</td>
                <td>
                    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" 
                        ControlToValidate="TextBox1" ErrorMessage="RegularExpressionValidator" 
                        ValidationExpression="^[0-9]{1,20}$" style="color: #FF0000" 
                        ValidationGroup="phone">僅限數字</asp:RegularExpressionValidator>
                </td>
            </tr>
            <tr>
                <td class="style5" colspan="2">
                    目前學生：</td>
            </tr>
            <tr>
                <td class="style4" colspan="2">
                    <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" 
                        CellPadding="4" DataKeyNames="StudentId" DataSourceID="SqlDataSource3" 
                        ForeColor="#333333" GridLines="None" Height="50px" Width="194px">
                        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                        <CommandRowStyle BackColor="#E2DED6" Font-Bold="True" />
                        <EditRowStyle BackColor="#999999" />
                        <FieldHeaderStyle BackColor="#E9ECF1" Font-Bold="True" />
                        <Fields>
                            <asp:BoundField DataField="StudentId" HeaderText="學生證號" ReadOnly="True" 
                                SortExpression="StudentId" />
                            <asp:BoundField DataField="StudentName" HeaderText="學生姓名" 
                                SortExpression="StudentName" />
                            <asp:BoundField DataField="DepartmentName" HeaderText="系別" 
                                SortExpression="DepartmentName" />
                        </Fields>
                        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                    </asp:DetailsView>
                    <asp:SqlDataSource ID="SqlDataSource3" runat="server" 
                        ConnectionString="<%$ ConnectionStrings:ProjectConnectionString %>" 
                        SelectCommand="SELECT Student.StudentId, Student.StudentName, Student.DepartmentId, Department.DepartmentName FROM Student INNER JOIN Department ON Student.DepartmentId = Department.DepartmentId WHERE (Student.StudentId = @StudentId)">
                        <SelectParameters>
                            <asp:ControlParameter ControlID="TextBox1" Name="StudentId" PropertyName="Text" 
                                Type="Int32" />
                        </SelectParameters>
                    </asp:SqlDataSource>
                </td>
            </tr>
            <tr>
                <td class="style7" colspan="2">
                    選取欲新增技能：</td>
            </tr>
            <tr>
                <td colspan="2">
                    <br />
                    <asp:DropDownList ID="DropDownList1" runat="server" 
                        DataSourceID="SqlDataSource2" DataTextField="SkillName" 
                        DataValueField="SkillId">
                    </asp:DropDownList>
&nbsp;
                    <asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="新增" />
                    <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
                        ConnectionString="<%$ ConnectionStrings:ProjectConnectionString %>" 
                        SelectCommand="SELECT * FROM [Skills] WHERE ([SkillId] &lt;&gt; @SkillId)">
                        <SelectParameters>
                            <asp:Parameter DefaultValue="3" Name="SkillId" Type="Int32" />
                        </SelectParameters>
                    </asp:SqlDataSource>
                    <asp:SqlDataSource ID="SqlDataSource4" runat="server" 
                        ConnectionString="<%$ ConnectionStrings:ProjectConnectionString %>" 
                        DeleteCommand="DELETE FROM [Has_Ski] WHERE [serial] = @serial" 
                        InsertCommand="INSERT INTO [Has_Ski] ([StudentId], [SkillId]) VALUES (@StudentId, @SkillId)" 
                        SelectCommand="SELECT * FROM [Has_Ski]" 
                        UpdateCommand="UPDATE [Has_Ski] SET [StudentId] = @StudentId, [SkillId] = @SkillId WHERE [serial] = @serial">
                        <DeleteParameters>
                            <asp:Parameter Name="serial" Type="Int32" />
                        </DeleteParameters>
                        <InsertParameters>
                            <asp:ControlParameter ControlID="DetailsView1" Name="StudentId" 
                                PropertyName="Rows[0].Cells[1].Text" Type="Int32" />
                            <asp:ControlParameter ControlID="DropDownList1" Name="SkillId" 
                                PropertyName="SelectedValue" Type="Int32" />
                        </InsertParameters>
                        <UpdateParameters>
                            <asp:Parameter Name="StudentId" Type="Int32" />
                            <asp:Parameter Name="SkillId" Type="Int32" />
                            <asp:Parameter Name="serial" Type="Int32" />
                        </UpdateParameters>
                    </asp:SqlDataSource>
                </td>
            </tr>
            <tr>
                <td class="style6" colspan="2">
                    該學生已有技能：</td>
            </tr>
            <tr>
                <td colspan="2">
                    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
                        DataSourceID="SqlDataSource1" Width="346px" CellPadding="4" 
                        ForeColor="#333333" GridLines="None">
                        <AlternatingRowStyle BackColor="White" />
                        <Columns>
                            <asp:BoundField DataField="SkillName" HeaderText="名稱" 
                                SortExpression="SkillName" />
                            <asp:BoundField DataField="Intro" HeaderText="介紹" 
                                SortExpression="Intro" />
                        </Columns>
                        <EditRowStyle BackColor="#7C6F57" />
                        <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
                        <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
                        <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
                        <RowStyle BackColor="#E3EAEB" />
                        <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
                        <SortedAscendingCellStyle BackColor="#F8FAFA" />
                        <SortedAscendingHeaderStyle BackColor="#246B61" />
                        <SortedDescendingCellStyle BackColor="#D4DFE1" />
                        <SortedDescendingHeaderStyle BackColor="#15524A" />
                    </asp:GridView>
                    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                        ConnectionString="<%$ ConnectionStrings:ProjectConnectionString %>" 
                        
                        SelectCommand="SELECT Has_Ski.StudentId, Has_Ski.SkillId, Skills.SkillName, Skills.Intro FROM Has_Ski INNER JOIN Skills ON Has_Ski.SkillId = Skills.SkillId WHERE (Has_Ski.StudentId = @StudentId) AND (Has_Ski.SkillId &lt;&gt; @id)">
                        <SelectParameters>
                            <asp:ControlParameter ControlID="TextBox1" Name="StudentId" PropertyName="Text" 
                                Type="Int32" />
                            <asp:Parameter DefaultValue="3" Name="id" />
                        </SelectParameters>
                    </asp:SqlDataSource>
                </td>
            </tr>
        </table>
        <br />
        <br />
        <br />
        <br />
        <br />
    
    </div>
    </form>
</body>
</html>
